package cn.starlightsoftware.sherly.service.permission;

import cn.hutool.core.bean.BeanUtil;
import cn.starlightsoftware.sherly.controller.admin.permission.vo.PermissionSaveReqVO;
import cn.starlightsoftware.sherly.db.mapper.permission.PermissionMapper;
import cn.starlightsoftware.sherly.db.model.permission.PermissionDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 谷子毅
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private PermissionMapper permissionMapper;

    @Override
    public void save(PermissionSaveReqVO reqVO) {
        permissionMapper.insert(BeanUtil.copyProperties(reqVO, PermissionDO.class));
    }

    @Override
    public PermissionDO detail(String permissionId) {
        return permissionMapper.selectById(permissionId);
    }

    @Override
    public void delete(String permissionId) {
        permissionMapper.deleteById(permissionId);
    }

    @Override
    public void update(PermissionSaveReqVO reqVO) {
        permissionMapper.updateById(BeanUtil.copyProperties(reqVO, PermissionDO.class));
    }

    @Override
    public List<PermissionDO> list() {
        return permissionMapper.selectList();
    }
}
